package edu.upol.paradise.compiler;

import java.util.HashMap;

import edu.upol.paradise.runtime.ParadiseRuntime;
import edu.upol.paradise.compiler.ParadiseCompiledBlockStub.ExecutionStatus;
import edu.upol.paradise.compiler.types.ParadiseObject;
import edu.upol.paradise.compiler.types.VariablePassingWrapper;

/**
 * ParadiseCompiledBlock is a compiled block of ParadiScheme into java bytecode represented by a class instance 
 * with code compiled inside.
 * @author P. Vanusanik <admin@en-circle.com>
 *
 */
public interface ParadiseCompiledBlock {
	
	/**
	 * Sets the runtime of the block.
	 * @param runtime
	 */
	public void setRuntime(ParadiseRuntime runtime);

	/**
	 * Initializes passed arguments to the block, if any
	 * @param wrapper Passed arguments to the block
	 * @throws Exception
	 */
	public void initializeVariables(VariablePassingWrapper wrapper)	throws Exception;

	/**
	 * Starts the execution of the block
	 */
	public void run();
	
	/**
	 * Requests halt of the current execution at next execution point
	 */
	public void requestHalt();

	/**
	 * Returns the last executed position in the generated bytecode
	 * @return
	 */
	public int getLastExecutionPoint();

	/**
	 * Returns execution status
	 * @return
	 */
	public ExecutionStatus getStatus();

	/**
	 * Returns result of the execution (NIL if none)
	 * @return
	 */
	public ParadiseObject getResult();

	/**
	 * Returns exception if any happened during the execution
	 * @return
	 */
	public Throwable getException();

	/**
	 * Returns mappings for block variables
	 * @return
	 */
	public HashMap<String, ParadiseObject> getBlockVariableMappings();
	
	/**
	 * Returns hashmap containing closure variables
	 * @return
	 */
	public HashMap<String, ParadiseObject> getClosureVariables();
	
	/**
	 * Returns constants
	 * @return
	 */
	public ParadiseObject[] getConstants();
	
	/**
	 * Returns active stack
	 * @return
	 */
	public ParadiseObject getTop();
	
	/**
	 * Returns locals array (or null if not interrupted) that is stored when interrupt happens for any reason.
	 * @return array or null
	 */
	public Object[] getLocals();
}